﻿Public Class Pedido : Implements IEquatable(Of Pedido)
    Private _NombreCliente As String
    Private _Fecha As Date
    Private _ListaProductos As New List(Of ProductoPedido)

    Public Sub New(ByVal nombreCliente As String, ByVal fecha As Date, ByVal listaProductos As List(Of ProductoPedido))
        Me.NombreCliente = nombreCliente
        Me.Fecha = fecha
        For i As Integer = 0 To listaProductos.Count - 1
            Me._ListaProductos.Add(listaProductos(i))

        Next


    End Sub

    Public Function PrecioTotal() As Decimal
        Dim total As Decimal
        For i As Integer = 0 To _ListaProductos.Count - 1
            total = total + _ListaProductos(i).Precio
        Next
        Return total
    End Function
    Public Property NombreCliente As String
        Get
            Return _NombreCliente
        End Get
        Set(value As String)
            Dim cli As New Cliente
            cli.Nombre = value
            Dim gest As New GestionClientes
            If gest.Clientes.Contains(cli) Then
                _NombreCliente = value
            Else
                _NombreCliente = "Error"
            End If

        End Set
    End Property
    Public Property Fecha As Date
        Get
            Return _Fecha
        End Get
        Set(value As Date)
            If value > Today Then
                _Fecha = Today
            Else
                _Fecha = value
            End If
        End Set
    End Property
    Public ReadOnly Property ListaProductos As ObjectModel.ReadOnlyCollection(Of ProductoPedido)
        Get
            Return _ListaProductos.AsReadOnly
        End Get
    End Property
    Public Overloads Function Equals(ByVal other As Pedido) As Boolean Implements System.IEquatable(Of Pedido).Equals
        Return other IsNot Nothing AndAlso Me.NombreCliente = other.NombreCliente AndAlso Me.Fecha = other.Fecha
    End Function
    Public Sub New()

    End Sub
End Class

